/*
 * @Author: WuFeng <763467339@qq.com>
 * @Date: 2024-10-10 14:38:28
 * @LastEditTime: 2024-11-18 15:29:54
 * @LastEditors: WuFeng <763467339@qq.com>
 * @Description:
 * @FilePath: \markdown-magic\src-tauri\src\main.rs
 * Copyright 版权声明
 */
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
use std::process::Command;

#[tauri::command]
fn call_python_script(url: &str) -> Result<String, String> {
    let output = Command::new("py")
        .arg("python/example.py")
        .arg(url)
        .output()
        .map_err(|e| format!("Failed to execute script: {}", e))?;

    if output.status.success() {
        Ok(String::from_utf8(output.stdout)
            .map_err(|e| format!("Invalid UTF-8 sequence: {}", e))?)
    } else {
        Err(String::from_utf8(output.stderr).unwrap_or_else(|_| "Unknown error".to_string()))
    }
}
use tauri::Builder;

fn main() {
    Builder::default()
        .invoke_handler(tauri::generate_handler![call_python_script])
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}
